package components;

import items.Item;
import entities.Entity;

public abstract class Weapon extends Item {

	protected float timeout;

	protected float shotTimer;

	protected boolean tryShooting = false;

	public Weapon(Entity e, float frequency) {
		super(e, ItemType.WEAPON);
		this.timeout = 1.0f / frequency;
		shotTimer = 0;
	}

	@Override
	public void tick(float dt) {
		if (tryShooting) {
			if (shotTimer >= timeout) {
				shoot();
				shotTimer = 0;
			}
			tryShooting = false;
		}
		shotTimer += dt;
	}

	@Override
	public void use() {
		tryShooting = true;
	}

	public abstract void shoot();

}
